package 笔试.便利蜂;

import java.util.Scanner;

/**
 * @author:谢君臣
 * @Date:2021/9/29-18:22
 * @version:1.0
 * @function:
 */
public class Main02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] line1 = scanner.nextLine().split(",");
        String[] line2 = scanner.nextLine().split(";");
        int n = Integer.parseInt(line1[0]);
        int [][] map = new int[n][n];
        for (String s : line2) {
            String[] top = s.split(",");
            int x = Integer.parseInt(top[0]);
            int y = Integer.parseInt(top[1]);
            map[x-1][y-1] = 1;
        }
        find(map);
        System.out.println();
    }
    public static int find(int[][] map){
        int pro = map.length;
        boolean[] vis = new boolean[pro];
        int cri =0;
        for (int i = 0; i < pro; i++) {
            if (!vis[i]){
                dfs(map,vis,pro,i);
                cri++;
            }
        }
        return cri;
    }

    private static void dfs(int[][] map, boolean[] vis, int pro, int i) {
        for (int j = 0; j < pro; j++) {
            if (map[i][j]==1&&!vis[j]){
                vis[j] = true;
                dfs(map, vis, pro, j);
            }
        }
    }
}
